import { ref } from 'vue'
import { RoleApi } from '@/apis'

/** 角色模块 */
export function useRole(options?: { onSuccess?: () => void }) {
  const loading = ref(false)
  const roleList = ref<RoleApi.RoleResp[]>([])

  const getRoleList = async () => {
    try {
      loading.value = true
      roleList.value = await RoleApi.getList({
        sort: ['sort,asc'],
      })
      options?.onSuccess?.()
    } finally {
      loading.value = false
    }
  }
  return { roleList, getRoleList, loading }
}
